home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
2.2
/
New-Bit-Editor.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
15KB
|
509 lines
" NAME New-Bit-Editor
AUTHOR tph@cs.man.ac.uk
FUNCTION much improved
ST-VERSIONS 2.2
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.1
DATE 22 Jan 1989
SUMMARY New-Bit-Editor
is a new, improved (or at least different :-)
version of the bit editor. In fact, it has been completely
re-written, rather more cleanly (IMHO).
This version allows you to set and reset pixels with the red and
yellow buttons respectively, has buttons (rather than a pop-up
menu) for save (accept) and undo (cancel), displays a grid (if the
scale factor is large enough), and displays the pixels in `gray'
(so that you don't lose the croshair cursor all the time). Editing
OpaqueForms is also supported, and you can set the `colour' (black,
white or transparent) associated with the red and yellow buttons.
A `full colour' version is due RSN.
Comments would be appreciated. TPH, 8/7/89.(2.2)
"!
Model subclass: #NewBitEditor
instanceVariableNames: 'form backupForm redButtonColor yellowButtonColor '
classVariableNames: ''
poolDictionaries: ''
category: 'New Bit Editor'!
NewBitEditor comment:
'I represent a `holder'' for a form being edited. I keep a backup
form, upon which changes are actually made, so that save and
restore operations can be performed.'!
!NewBitEditor methodsFor: 'initialize-release'!
initialize
"Initialize the red and yellow button colors."
redButtonColor _ 1.
yellowButtonColor _ 0.! !
!NewBitEditor methodsFor: 'accessing'!
backupForm
"Answer with the (backup) form being edited."
^backupForm!
form
"Answer with the (real) form being edited."
^form!
pixelAt: aPoint
"Get the pixel at aPoint."
^backupForm valueAt: aPoint!
redButtonColor
^redButtonColor!
redButtonColor: aValue
redButtonColor _ aValue!
setPixelAt: aPoint to: aValue
"Set the pixel at aPoint to aValue."
(backupForm valueAt: aPoint) = aValue ifFalse: [
backupForm valueAt: aPoint put: aValue.
self changed: aPoint.
backupForm changed]!
yellowButtonColor
^yellowButtonColor!
yellowButtonColor: aValue
yellowButtonColor _ aValue! !
!NewBitEditor methodsFor: 'form manipulation'!
restore
"Restore the backup form from the (real) form."
backupForm become: form deepCopy.
backupForm changed.
self changed: #all!
save
"Save the backup form on the (real) form."
form become: backupForm.
backupForm become: form deepCopy! !
!NewBitEditor methodsFor: 'private'!
setForm: aForm
form _ aForm.
backupForm _ aForm deepCopy! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
NewBitEditor class
instanceVariableNames: ''!
!NewBitEditor class methodsFor: 'instance creation'!
new
"Answer with a new initialized instance of the receiver."
^super new initialize!
on: aForm
"Answer with a new instance of the receiver on aForm."
^self new setForm: aForm! !
MouseMenuController subclass: #NewBitEditorController
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'New Bit Editor'!
NewBitEditorController comment:
'I am a controller for a simple bit-oriented form editor. I handle
input from red and yellow buttons, and pass it over to my model.'!
!NewBitEditorController methodsFor: 'basic control sequence'!
controlInitialize
"Change the cursor when starting."
Cursor crossHair show!
controlTerminate
"Restore the cursor when stoping."
Cursor normal show! !
!NewBitEditorController methodsFor: 'control defaults'!
isControlActive
^(view containsPoint: sensor cursorPoint) and: [sensor blueButtonPressed not]! !
!NewBitEditorController methodsFor: 'button actions'!
redButtonActivity
"When the red button is pressed, determine the location of the
cursor, and set the corresponding pixel in the model's (backup) form."
model
setPixelAt: sensor cursorPoint -
(view insetDisplayBox topLeft) // view scaleFactor
to: model redButtonColor!
yellowButtonActivity
"When the yellow button is pressed, determine the location of the
cursor, and set the corresponding pixel in the model's (backup) form."
model
setPixelAt: sensor cursorPoint -
(view insetDisplayBox topLeft) // view scaleFactor
to: model yellowButtonColor! !
View subclass: #NewBitEditorView
instanceVariableNames: 'scaleFactor blackForm whiteForm transparentForm maskForm '
classVariableNames: ''
poolDictionaries: ''
category: 'New Bit Editor'!
NewBitEditorView comment:
'I am a View on a form being edited. I know the scale factor
being used, and retain various mask forms in improve the performance
of the display.'!
!NewBitEditorView methodsFor: 'accessing'!
blackForm
"Answer with an appropriate black form of displaying."
blackForm isNil ifTrue: [
blackForm _ (Form extent: scaleFactor) gray.
blackForm black: ((scaleFactor x - 1) @ 0 corner: scaleFactor).
blackForm black: (0 @ (scaleFactor y - 1) corner: scaleFactor)].
^blackForm!
maskForm
| lineForm |
maskForm isNil ifTrue: [
maskForm _ Form extent: self insetDisplayBox extent.
lineForm _ Form extent: scaleFactor.
lineForm black: ((scaleFactor x - 1) @ 0 corner: scaleFactor).
lineForm black: (0 @ (scaleFactor y - 1) corner: scaleFactor).
(InfiniteForm with: lineForm) displayOn: maskForm].
^maskForm!
scaleFactor
"Answer with the scaleFactor."
^scaleFactor!
transparentForm
"Answer with an appropriate `transparent' form for displaying."
transparentForm isNil ifTrue: [
transparentForm _ (Form extent: scaleFactor) veryLightGray.
transparentForm black: ((scaleFactor x - 1) @ 0 corner: scaleFactor).
transparentForm black: (0 @ (scaleFactor y - 1) corner: scaleFactor)].
^transparentForm!
whiteForm
"Answer with an appropriate white form of displaying."
whiteForm isNil ifTrue: [
whiteForm _ Form extent: scaleFactor.
whiteForm black: (scaleFactor x - 1 @ 0 corner: scaleFactor).
whiteForm black: (0 @ (scaleFactor y - 1) corner: scaleFactor)].
^whiteForm! !
!NewBitEditorView methodsFor: 'controller access'!
defaultControllerClass
^NewBitEditorController! !
!NewBitEditorView methodsFor: 'displaying'!
displayForm
"The model holds a Form. Display it appropriately."
(model backupForm magnifyBy: scaleFactor)
displayOn: Display
at: self insetDisplayBox topLeft
clippingBox: self insetDisplayBox
rule: Form over
mask: Form gray!
displayFormAt: aPoint
"Update the display at aPoint."
| tempForm |
(model pixelAt: aPoint) = 0
ifTrue: [tempForm _ self whiteForm].
(model pixelAt: aPoint) = 1
ifTrue: [tempForm _ self blackForm].
(model pixelAt: aPoint) = 2
ifTrue: [tempForm _ self transparentForm].
tempForm notNil ifTrue: [
tempForm
displayOn: Display
at: (self insetDisplayBox origin + (scaleFactor * aPoint))
clippingBox: self insetDisplayBox
rule: Form over
mask: Form black]!
displayGrid
"Display the grid appropriately."
self maskForm
displayOn: Display
at: self insetDisplayBox topLeft
clippingBox: self insetDisplayBox
rule: Form paint
mask: Form black!
displayOpaqueForm
"The model holds an OpaqueForm. Display it appropriately."
| tempForm |
tempForm _ Form extent: self insetDisplayBox extent.
(InfiniteForm with: Form veryLightGray) displayOn: tempForm.
tempForm
displayOn: Display
at: self insetDisplayBox origin
clippingBox: self insetDisplayBox
rule: Form over
mask: Form black.
(model backupForm shape magnifyBy: scaleFactor)
displayOn: Display
at: self insetDisplayBox topLeft
clippingBox: self insetDisplayBox
rule: Form erase
mask: Form black.
(model backupForm figure magnifyBy: scaleFactor)
displayOn: Display
at: self insetDisplayBox topLeft
clippingBox: self insetDisplayBox
rule: Form under
mask: Form gray!
displayView
"Display the model appropriately."
(model backupForm isKindOf: OpaqueForm)
ifTrue: [self displayOpaqueForm]
ifFalse: [self displayForm].
scaleFactor > (5@5) ifTrue: [self displayGrid]! !
!NewBitEditorView methodsFor: 'updating'!
update: aParameter
"Ignore aParameter, and re-display the view."
aParameter == #all ifTrue: [^self display].
(aParameter isKindOf: Point) ifTrue: [self displayFormAt: aParameter].! !
!NewBitEditorView methodsFor: 'private'!
setScaleFactor: aPoint
scaleFactor _ aPoint.! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
NewBitEditorView class
instanceVariableNames: ''!
!NewBitEditorView class methodsFor: 'instance creation'!
openOn: aForm
"Create and schedule a new instance of the receiver, using a
default magnification factor."
"NewBitEditorView openOn: Form fromUser."
"NewBitEditorView openOn: Cursor crossHair."
"NewBitEditorView openOn: (OpaqueForm shape: Cursor normal deepCopy)."
self openOn: aForm withMagnification: 8@8!
openOn: aForm withMagnification: aPoint
"Create and schedule a new instance of the receiver."
"NewBitEditorView openOn: (Form extent: 40@40) withMagnification: (6@6). "
"NewBitEditorView openOn: (Cursor wait) withMagnification: (8@8)."
"NewBitEditorView openOn: Form fromUser withMagnification: (10@10)."
"NewBitEditorView openOn: OpaqueForm makeStar."
| topView extra size topSize editor bitView buttonView |
topView _ StandardSystemView new label: 'Bit Editor'.
size _ aForm extent * aPoint + (2@2).
extra _ (aForm isKindOf: OpaqueForm)
ifTrue: [100 max: aForm extent x + 20]
ifFalse: [50 max: aForm extent x + 10].
topSize _ size + (extra @ 0).
editor _ NewBitEditor on: aForm.
topView minimumSize: topSize.
topView maximumSize: topSize.
topView borderWidth: 1.
topView borderColor: Form black.
topView window: (0@0 extent: topSize).
topView insideColor: Form white.
buttonView _ View new borderWidth: 1.
buttonView model: editor.
buttonView borderColor: Form black.
buttonView insideColor: Form lightGray.
topView
addSubView: buttonView
window: (size x @ 0 corner: topSize)
viewport: (size x @ 0 corner: topSize).
(aForm isKindOf: OpaqueForm)
ifTrue: [self addOpaqueFormSubViewsTo: buttonView]
ifFalse: [self addFormSubViewsTo: buttonView].
bitView _ self new model: editor.
bitView borderWidth: 1.
bitView borderColor: Form black.
bitView setScaleFactor: aPoint.
topView
addSubView: bitView
window: (0 @ 0 extent: size)
viewport: (0 @ 0 extent: size).
topView controller open! !
!NewBitEditorView class methodsFor: 'private'!
addFormSubViewsTo: aView
"Insert buttons and subviews into aView, appropriate for editing a Form"
| button buttonView formView |
button _ Button newOff.
buttonView _ SwitchView new model: button.
button onAction: [aView model save].
buttonView label: 'save' asText allBold asParagraph asForm.
buttonView borderWidth: 2.
buttonView window: (buttonView defaultWindow origin
extent: (buttonView defaultWindow extent x @
(buttonView defaultWindow extent y min:
(aView viewport extent y * 0.2)))).
aView
addSubView: buttonView
align: buttonView window center
with: aView viewport center x @ (aView viewport topCenter y +
(aView viewport height * 0.13)).
button _ Button newOff onAction: [aView model restore].
buttonView _ SwitchView new model: button.
buttonView borderWidth: 2.
buttonView label: 'undo' asText allBold asParagraph asForm.
buttonView window: (buttonView defaultWindow origin
extent: (buttonView defaultWindow extent x @
(buttonView defaultWindow extent y min:
(aView viewport extent y * 0.2)))).
aView
addSubView: buttonView
align: buttonView window center
with: aView viewport center x @ (aView viewport topCenter y +
(aView viewport height * 0.35)).
formView _ FormView new
model: aView model backupForm
controller: NoController new.
formView borderWidthLeft: 2 right: 0 top: 2 bottom: 0.
formView borderColor: Form black.
formView insideColor: Form white.
formView window: (formView defaultWindow expandBy: (2@2 extent: 2@2)).
aView addSubView: formView
align: formView window bottomRight
with: aView viewport bottomRight!
addOpaqueFormSubViewsTo: aView
"Insert buttons and subviews into aView, appropriate for editing
an OpaqueForm."
| window button buttonView formView |
button _ Button newOff.
buttonView _ SwitchView new model: button.
button onAction: [aView model save].
buttonView label: 'save' asText allBold asParagraph asForm.
buttonView borderWidth: 2.
window _ buttonView defaultWindow origin
extent: (buttonView defaultWindow extent x @
(buttonView defaultWindow extent y min:
(aView viewport extent y * 0.2))).
buttonView window: window.
aView
addSubView: buttonView
align: buttonView window rightCenter
with: (aView viewport center x - 5) @ (aView viewport topCenter y +
(aView viewport height * 0.13)).
button _ Button newOff onAction: [aView model restore].
buttonView _ SwitchView new model: button.
buttonView borderWidth: 2.
buttonView label: 'undo' asText allBold asParagraph asForm.
buttonView window: window.
aView
addSubView: buttonView
align: buttonView window leftCenter
with: (aView viewport center x + 5) @ (aView viewport topCenter y +
(aView viewport height * 0.13)).
button _ Button newOff.
buttonView _ SwitchView new model: button.
buttonView borderWidth: 2.
buttonView insideColor: Form white.
buttonView window: window.
button onAction: [
aView model yellowButtonColor: (aView model yellowButtonColor + 1 \\ 3).
aView model yellowButtonColor = 0 ifTrue: [
buttonView insideColor: Form white].
aView model yellowButtonColor = 1 ifTrue: [
buttonView insideColor: Form gray].
aView model yellowButtonColor = 2 ifTrue: [
buttonView insideColor: Form veryLightGray]].
button offAction: [buttonView displayView].
aView
addSubView: buttonView
align: buttonView window leftCenter
with: (aView viewport center x + 5) @ (aView viewport topCenter y +
(aView viewport height * 0.35)).
button _ Button newOff.
buttonView _ SwitchView new model: button.
buttonView borderWidth: 2.
buttonView insideColor: Form gray.
buttonView window: window.
button onAction: [
aView model redButtonColor: (aView model redButtonColor + 1 \\ 3).
aView model redButtonColor = 0 ifTrue: [
buttonView insideColor: Form white].
aView model redButtonColor = 1 ifTrue: [
buttonView insideColor: Form gray].
aView model redButtonColor = 2 ifTrue: [
buttonView insideColor: Form veryLightGray]].
button offAction: [buttonView displayView].
aView
addSubView: buttonView
align: buttonView window rightCenter
with: (aView viewport center x - 5) @ (aView viewport topCenter y +
(aView viewport height * 0.35)).
formView _ FormView new
model: aView model backupForm
controller: NoController new.
formView borderWidthLeft: 2 right: 0 top: 2 bottom: 0.
formView borderColor: Form black.
formView insideColor: Form white.
formView window: (formView defaultWindow expandBy: (2@2 extent: 2@2)).
aView addSubView: formView
align: formView window bottomRight
with: aView viewport bottomRight! !